<?php
/**
 * From Rob Allen's Zend tutorial http://akrabat.com/zend-framework-tutorial/
 * and
 * http://www.zfsnippets.com/snippets/view/id/4
 */
class Zend_View_Helper_BaseUrl extends Zend_View_Helper_Abstract 
{
    /**
     * @var string
     */
    protected $_baseUrl;
    
    public function baseUrl()
    {
        if (null === $this->_baseUrl) {
            if ($baseUrl = Zend_Registry::get('config')->baseUrl) {
                $this->_baseUrl = $baseUrl;
            } elseif (isset($this->view->baseUrl)) {
                $this->_baseUrl = $this->view->baseUrl;
            } else {
                $request = Zend_Controller_Front::getInstance()->getRequest();
                $this->_baseUrl = $request->getBaseUrl();
            }
        }

        return $this->_baseUrl;
   	}
}
